
package com.example.visitedsys.Controller;

import com.example.visitedsys.FileConfig.Analysis;
import com.example.visitedsys.Shrio.Bean.ResponseBean;
import com.example.visitedsys.service.ExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * @author  SongPeng
 * @date  2021/10/19 14:20
 * @version 1.0
 */

@RestController
@RequestMapping("/File")
public class ImportFileController {
    @Autowired
    private ExcelService excelService;
    //接受文件上传
    @RequestMapping("/upload")
    public ResponseBean uploadFile(MultipartFile file){
        //解析excel文件
        List<ArrayList<String>> row = Analysis.analysis(file);
        //接收excel文件并处理数据
        excelService.ExcelInsert(row);
        //如果要上传到服务器的话
    /*String targetUrl = "D:\\MYURLFILE";
    try {
      file.transferTo(new File(targetUrl, fileName));
    } catch (IOException e) {
      e.printStackTrace();
      map.put("status","error");
    }*/
        return ResponseBean.success();
    }
}